#!/bin/bash
found=2

function line_exist() {
  line="$1"
  file="$2"
  # 如果找到line就返回2
  sed -n "s~${line}~~;tx;d;:x q${found}" "${file}"
}

function append_line() {
  line="$1"
  file="$2"
  line_exist "${line}" "${file}"
  if [ $? -eq ${found} ]
  then
    echo "${line} exist in ${file}"
  else
    echo "${line} >> ${file}"
    echo "${line}" >> conf/local.conf 
  fi
}

conf_file=conf/local.conf
if [ ! -e "${conf_file}" ]
then
  echo "${conf_file} not found"
fi

# 增加DL_DIR配置
line="DL_DIR = \"$HOME/download/yocto/downloads\""
append_line "${line}" "${conf_file}"

# 增加SSTATE_DIR配置
line="SSTATE_DIR = \"$HOME/download/yocto/sstate-cache\""
append_line "${line}" "${conf_file}"
